package com.logic.saas.pojo;
import java.io.Serializable;

import org.apache.commons.lang3.StringUtils;

import com.logic.saas.util.SysUtil;
import com.logic.saas.util.annotation.Column;
import com.logic.saas.util.annotation.Table;
import com.logic.saas.util.annotation.UniqueConstraint;


@Table(name = "code", uniqueConstraints={@UniqueConstraint(columnNames={"kind_id","short_name"})})
public class Qcode extends BasePojo implements Serializable {
    private static final long serialVersionUID = 3148176768559230877L;
    

    @Column(name = "kind_id",  source = "kind.id")
    private Kind kind;
    @Column(name = "short_name")
	private String shortName;
    @Column(name = "full_name")
	private String fullName;
    @Column(name = "priority")
	private Integer priority;
	

	public String getShortName() {
		return shortName;
	}
	public void setShortName(String shortName) {
		this.shortName = shortName;
	}
	public String getFullName() {
		return fullName;
	}
	public void setFullName(String fullName) {
		this.fullName = fullName;
	}
	
	public Kind getKind() {
		return kind;
	}
	public void setKind(Kind kind) {
		this.kind = kind;
	}
	
	public Integer getPriority() {
		return priority;
	}
	public void setPriority(Integer priority) {
		this.priority = priority;
	}
	@Override
	public String getDisplayText() {
		if(StringUtils.isNotBlank(shortName)){
			String tempStr="["+shortName.trim()+"] "+SysUtil.trim(fullName);
		    return SysUtil.cutoffString(tempStr,displayTextLength);
		}else
			return "";
	}
	
	/**
	 * 重写equal方法，比较Qcode是否相等,不比ID
	 */
	@Override
	public boolean equals(Object obj) {
		boolean equal = false;
		
		if(obj != null){
			if(this.getClass() == obj.getClass()){
				Qcode k = (Qcode) obj;
				if(
					//((this.getId() == null && k.getId() == null) || (this.getId() != null && k.getId() != null && this.getId().equals(k.getId()))) &&
					((this.getKind() == null && k.getKind() == null) || (this.getKind() != null && k.getKind() != null && this.getKind().equals(k.getKind()))) &&
					((this.getShortName() == null && k.getShortName() == null) || (this.getShortName() != null && k.getShortName() != null && this.getShortName().equals(k.getShortName()))) &&
					((this.getFullName() == null && k.getFullName() == null) || (this.getFullName() != null && k.getFullName() != null && this.getFullName().equals(k.getFullName()))) &&
					((this.getPriority() == null && k.getPriority() == null) || (this.getPriority() != null && k.getPriority() != null && this.getPriority().equals(k.getPriority())))
				 ){
					equal = true;
				}
			}
		}
		
		return equal;
	}
}

